package com.suredy.app.software.model;

import java.io.File;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

import com.suredy.core.model.BaseModel;

/**
 * 常用软件
 * 
 * @author VIVID.G
 * @since 2016-4-4
 * @version v0.1
 */
@Entity
@Table(name = "tb_software")
public class Software extends BaseModel {

	private static final long serialVersionUID = 1L;

	/* 文件名称 */
	@Column(length = 100, nullable = false)
	private String name;

	/* 版本 */
	@Column(length = 50, nullable = false)
	private String version;

	/* 文件相对路径 */
	@Column(length = 200, nullable = false)
	private String path;

	/* 上传时间 */
	@Column(name = "up_time")
	private Date upTime;

	/* 下载次数 */
	@Column(length = 200, nullable = false)
	private long downTimes;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Date getUpTime() {
		return upTime;
	}

	public void setUpTime(Date upTime) {
		this.upTime = upTime;
	}

	public long getDownTimes() {
		return downTimes;
	}

	public void setDownTimes(long downTimes) {
		this.downTimes = downTimes;
	}

	@Transient
	public String getPathForUrl() {
		if (StringUtils.isBlank(this.getPath()))
			return null;

		return this.getPath().replace(File.separatorChar, '/');
	}

}
